import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router'

const routes: RouteRecordRaw[] = [
  {
    path: '/',
    redirect: '/drug/list'
  },
  {
    path: '/drug',
    name: 'Drug',
    children: [
      {
        path: 'list',
        name: 'DrugList',
        component: () => import('@/views/drug/DrugList.vue'),
        meta: { title: '药品规则列表' }
      },
      {
        path: 'add',
        name: 'DrugAdd',
        component: () => import('@/views/drug/DrugForm.vue'),
        meta: { title: '新增药品规则' }
      },
      {
        path: 'edit/:id',
        name: 'DrugEdit',
        component: () => import('@/views/drug/DrugForm.vue'),
        meta: { title: '编辑药品规则' }
      },
      // 修正：路径参数改为 ruleId（与后端保持一致）
      {
        path: 'code/:ruleId', // 关键：用 ruleId 作为参数名
        name: 'DrugCode',
        component: () => import('@/views/drug/DrugCode.vue'),
        meta: { title: '药品代码关联列表' }
      }
    ]
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

export default router
